<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
	xmlns:uForum="urn:uForum"
	xmlns:uForum.raw="urn:uForum.raw"
	exclude-result-prefixes="uForum uForum.raw msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


<xsl:output method="html" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">

<xsl:if test="number($currentPage/data [@alias = 'forumAllowNewTopics']) = 1">

<xsl:variable name="p">
<xsl:choose>
<xsl:when test="string(number( umbraco.library:RequestQueryString('p') )) != 'NaN'">
<xsl:value-of select="umbraco.library:RequestQueryString('p')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="items">15</xsl:variable>
<xsl:variable name="pages" select="uForum:ForumPager($currentPage/@id, $items, $p)"/>

<xsl:variable name="topics" select="uForum.raw:Topics($currentPage/@id, $items, $p)//topic"/>

<xsl:if test="umbraco.library:IsLoggedOn()">
<div class="infoBox" id="newTopic">
<a href="{umbraco.library:NiceUrl($currentPage/@id)}/NewTopic">Create a new topic</a>
    <br/>
<small>Create a new topic in this forum</small>
</div>
</xsl:if>

<xsl:if test="count($topics) &gt; 0">
<table class="forumList" cellspacing="0">
<thead>
<tr>
<th>Topic</th><th class="replies">Replies</th><th>Last post</th>
</tr>
</thead>
<tbody>

<xsl:for-each select="$topics">
<xsl:sort select="updated" order="descending" />


	<xsl:call-template name="topic">
		<xsl:with-param name="collaps" select="false()" />
		<xsl:with-param name="topic" select="." />
	</xsl:call-template>



</xsl:for-each>
</tbody>
</table>

<xsl:if test="count($pages//page) &gt; 1">
<strong>Pages: </strong>
<ul class="pager">
<xsl:for-each select="$pages//page">
	<li>
		<xsl:if test="@current = 'true'">
			<xsl:attribute name="class">current</xsl:attribute>
		</xsl:if>
		<a href="?p={@index}"><xsl:value-of select="@index + 1"/></a>	
	</li>
</xsl:for-each>
</ul>
</xsl:if>

</xsl:if>

</xsl:if>
</xsl:template>

<xsl:template name="collapsedTopic">
<xsl:param name="topic"/>

<tr class="toggleTopic" id="collapsedtopic{$topic/id}">
	<td colspan="3">
		The topic <em><xsl:value-of select="$topic/title"/></em> by <em>
		<xsl:value-of select="umbraco.library:GetMemberName($topic/memberId)"/></em> 
		has a very low score and been hidden, <a class="forumToggleTopic" rel="topic{$topic/id}" href="#">Show it anyway</a>
	</td>
</tr>

<xsl:call-template name="topic">
	<xsl:with-param name="collaps" select="true()" />
	<xsl:with-param name="topic" select="$topic" />
</xsl:call-template>

</xsl:template>

<xsl:template name="topic">
<xsl:param name="collaps"/> 
<xsl:param name="topic"/>

<tr id="topic{$topic/id}">
<xsl:if test="$collaps"><xsl:attribute name="class">hidden</xsl:attribute></xsl:if>
<xsl:if test="not($collaps) and $topic/answer != 0">
<xsl:attribute name="class">solved</xsl:attribute>
</xsl:if>

<th class="title">

<a href="{uForum:NiceTopicUrl($topic/id)}"><xsl:value-of select="$topic/title"/></a>
<small>
	Started by:  <xsl:value-of select="umbraco.library:GetMemberName($topic/memberId)"/>
	 - <xsl:value-of select="uForum:TimeDiff($topic/created)"/>
	<xsl:if test="$topic/answer != 0"><em>&nbsp; - Topic has been solved</em></xsl:if>	
</small>
</th>

<td class="replies"><xsl:value-of select="$topic/replies"/></td>
<td class="latestComment">
<a href="{uForum:NiceTopicUrl($topic/id)}">
<xsl:value-of select="uForum:TimeDiff($topic/updated)"/>
</a> by

<xsl:choose><xsl:when test="number($topic/latestReplyAuthor) &gt; 0"> 
 <xsl:value-of select="umbraco.library:GetMemberName($topic/latestReplyAuthor)"/>
</xsl:when>
<xsl:otherwise>
 <xsl:value-of select="umbraco.library:GetMemberName($topic/memberId)"/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>

</xsl:template>



</xsl:stylesheet>